package com.app.controller;

import com.app.domain.vo.ViewVo;
import com.app.framework.common.R;
import com.app.service.ViewService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Web访问控制器
 */
@RestController
@RequestMapping("/api/web")
public class ViewController {

    @Resource
    private ViewService viewService;

    /**
     * 增加系统访问量
     */
    @PostMapping("/look")
    public R<?> look() {
        viewService.look();
        return R.ok();
    }

    /**
     * 获取系统访问量
     */
    @GetMapping("/view")
    public R<Map<String, Object>> view() {
        Integer count = viewService.view();
        Map<String, Object> map = new HashMap<>(1);
        map.put("count", count);
        return R.ok(map);
    }

    /**
     * 网站信息统计
     */
    @GetMapping("/counts")
    public R<ViewVo> webCount() {
        return R.ok(viewService.webCount());
    }

}